/*
 * CProtocolFactory.h
 *
 *  Created on: 2011-9-20
 *      Author: stargui
 */

#ifndef CPROTOCOLFACTORY_H_
#define CPROTOCOLFACTORY_H_

#include <stdint.h>
#include <string>
#include "CommonLibrary.h"

typedef enum
{
	PAYLOAD_SIGNAL = 0,

	PAYLOAD_METADATA = 1,

	PAYLOAD_STREAM_TYPE_EM	,	//h264流实时视频

	PAYLOAD_VIDEO_TYPE_EM,		//流视频文件

	PAULOAD_REMOTE_PLAYBACK_TYPE_EM,	//远程同步回放

	PAYLOAD_AUDIO ,				//对讲音频

	PAYLOAD_JPEG ,

	PAYLOAD_RAWFILE ,			//文件

	PAYLOAD_UPGRADE,		//升级

	PAYLOAD_LOG,//日志9
} PAYLOAD_TYPE;

class CProtocolFactory
{

public:

	CProtocolFactory();

	virtual ~CProtocolFactory();

public:

	int PT();

	int SSRC();

	int Markbit();

	std::string CSRC();

	std::string EXT();

	std::string PAYLOAD();

	std::string Serialize(int pt, int ssrc, Json::Value &value, std::string csrc = "", std::string ext = "", int Mark = 1);

	std::string Serialize(int pt, int ssrc, std::string &value, std::string csrc = "", std::string ext = "", int Mark = 1);

	std::string Serialize(int pt, int ssrc, int datalen = 0, std::string csrc = "", int extlen = 0, int Mark = 1);

	char*  Serialize(char * csrc ,int pt, int ssrc, int datalen = 0,  int extlen = 0, int Mark = 1);

	std::string Serialize(int pt,int ssrc,Json::Value &value,unsigned int datalen);

	long Deserialize(std::string &data);

private:

	struct
	{
		uint32_t V :2;
		uint32_t P :1;
		uint32_t M :1;
		uint32_t CSRC :4;
		uint32_t PT :8;
		uint32_t SSRC :16;
		uint32_t counts ;
		uint32_t reserve;//保留
	}__attribute__ ((__packed__)) _head;

	std::string _csrc, _extern, _payload;
};

#endif /* CPROTOCOLFACTORY_H_ */
